#pragma once
#include "Renderable.h"
#include "MovableObject.h"
#include "UpdateObject.h"
#include <vector>
class SubMesh;
class Mesh;
class Entity;
class SkeletonInstance;
class MaterialInstance;

class SubEntity : public Renderable
{
public:
	SubEntity(Entity* parent, SubMesh* subMesh);
	~SubEntity();

	const Entity* getParent() const { return mParent; }

	virtual VertexFactory* getVertexFactory();
	virtual MaterialInstance* getMaterial();
	virtual const IndexData* getIndexData() const;

	virtual size_t GetGpuSkinMatrix(Matrix3x4* xform) const;

private:
	Entity* mParent;
	const SubMesh* mSubMesh;
	MaterialInstance* mMaterialInstance;
};

class Entity : public MovableObject, public UpdateObject
{
	typedef std::vector<SubEntity*> SubEntityList;
public:
	Entity(const std::string& name, Scene* owner);
	~Entity();
	
	const std::string& getMeshName() const { return mMeshName; }
	const Mesh* getMesh() const { return mMesh; }
	const SkeletonInstance* getSkeletonInstance() const { return mSkeletonInstance; }
	SkeletonInstance* getSkeletonInstance() { return mSkeletonInstance; }

	virtual const char* getMovableType() const { return "Entity"; };

	virtual bool Init(const NameValeParamMap* params);
	virtual void AddToView(RenderView* view);
	virtual void UpdateTransform();
	virtual void Update(float elapsedTime);

protected:
	virtual void AddToScene();
	virtual void RemoveFromScene();

private:
	std::string mMeshName;
	const Mesh* mMesh;
	SkeletonInstance* mSkeletonInstance;
	SubEntityList mSubEntities;
};
